cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,      // The default value will be used only when the component attaching
        //                           to a node for the first time
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _xiazhuBt:null,
        fenOne:null,
        fenTwo:null
    },

    // use this for initialization
    onLoad: function () {
        if(cc.vv == null){
            return
        };
        // cc.vv.Jiaofen=this;
        this._xiazhuBt = this.node.getChildByName("xiazhuBt");
        this._xiazhuBt.active=false;
        cc.vv.utils.addClickEvent(this._xiazhuBt,this.node,"JiaoFen","onXiaZhuClick");
        
        var toutaoBts=this.node.getChildByName("toutaoBt");
        for (var i = 0; i < toutaoBts.childrenCount; i++) {
            var bt=toutaoBts.children[i].children[1];
            cc.vv.utils.addClickEvent(bt,this.node,"JiaoFen","onTouBtClick");
        };
        
        var ertaoBts=this.node.getChildByName("ertaoBt");
        for (var i = 0; i < ertaoBts.childrenCount; i++) {
            var bt=ertaoBts.children[i].children[1];
            cc.vv.utils.addClickEvent(bt,this.node,"JiaoFen","onErBtClick");
        };
        this.xiaZhuBtChange();
        var self=this;
        // 重置叫分数据和界面
        this.node.parent.parent.on('initJiaofen',function(){
            console.log("initJiaofen/jiaofen");
            self.fenOne=null;
            self.fenTwo=null;
            self.xiaZhuBtChange();
            self.initbts()
        });
    },
    // 下注按钮点击
    onXiaZhuClick:function(){
        console.log("onXiaZhuClick");
        var self=this;
        cc.vv.net.send("jiaofen",{fenOne:this.fenOne,fenTwo:this.fenTwo},function(){
            self.node.active=false
        })
    },
    // 头套按钮点击
    onTouBtClick:function(event){
        console.log("onTouBtClick");
        this.fenOne=parseInt(event.target.name);
        this.xiaZhuBtChange()
    },
    // 二套按钮点击
    onErBtClick:function(event){
        console.log("onErBtClick");
        this.fenTwo=parseInt(event.target.name);
        this.xiaZhuBtChange()
    },
    // 下注按钮显示
    xiaZhuBtChange:function(){
        if (this.fenOne>0) {
            if (this.fenTwo>0||this.fenTwo==0) {
                this._xiazhuBt.active=true
            }
        }else{
            this._xiazhuBt.active=false

        }
    },
    // 重置两套按钮的选中状态
    initbts:function(){
        var toutaoBts=this.node.getChildByName("toutaoBt");
        for (var i = 0; i < toutaoBts.childrenCount; i++) {
            var bt=toutaoBts.children[i].getComponent("RadioButton");
            bt.check(false)
        };
        
        var ertaoBts=this.node.getChildByName("ertaoBt");
        for (var i = 0; i < ertaoBts.childrenCount; i++) {
            var bt=ertaoBts.children[i].getComponent("RadioButton");
            bt.check(false)
        }
    }
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
